﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.IO;
using Seasar.Framework.Container.Factory;
using Shsc.Net.Common.Seasar.Extension.CustomAttribute;
using Shsc.Net.Web.Extension;

namespace Shsc.Net.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        const string LOG4NETFILEPATH = "log4net.FilePath";

        public static void RegisterRoutes(RouteCollection routes)
        {
            CacheAttribute.Cache = new System.Web.Caching.Cache();
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Login", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            String configPath = System.Configuration.ConfigurationSettings.AppSettings[LOG4NETFILEPATH];
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Server.MapPath(configPath)));
            SingletonS2ContainerFactory.Init();
            ControllerBuilder.Current.SetControllerFactory(typeof(SeasarControllerFactory));
            RegisterRoutes(RouteTable.Routes);
        }

        protected void Application_End()
        {
            SingletonS2ContainerFactory.Destroy();
        }
    }
}